<?php

namespace App\Http\Controllers\Client;

use App\Http\Controllers\Controller;
use App\Models\Key;
use Illuminate\Http\Request;

class KeyController extends Controller
{
    protected $keyModel;

    public function __construct()
    {
        $this->keyModel = new Key();
    }

    /**
     * 通过授权码获取某条关键信息
     */

        /**
         * @OA\Post(
         *     tags={"关键信息"},
         *     path="/client/key/getInfoByAuthCode",
         *     summary="获取项目相关的关键资料",
         *     description="通过授权码获取项目的关键资料",
         *     @OA\Parameter(
         *          name="authCode",
         *          description="授权码",
         *          in="query",
         *          required=true,
         *          @OA\Schema(
         *              type="string"
         *          )
         *     ),
         *     @OA\Parameter(
         *          name="key",
         *          description="关键信息类型",
         *          in="query",
         *          required=true,
         *          @OA\Schema(
         *              type="string"
         *          )
         *     ),
         *     @OA\Response(
         *           response=200,
         *           description="已获取weChatPwd的值",
         *           @OA\JsonContent(
         *              type="object",
         *              @OA\Property(property="code", type="number",description="状态码",default="200"),
         *              @OA\Property(property="msg", type="string",description="提示信息",default="已获取weChatPwd的值"),
         *              @OA\Property(property="data", type="object",
         *                  @OA\Property(property="weChatPwd", type="string"),
         *                  @OA\Property(property="144090060Hyk", type="string"),
         *              ),
         *           )
         *     ),
         *     @OA\Response(
         *          response=5001,
         *          description="关键资料获取失败",
         *          @OA\JsonContent(
         *              type="object",
         *              @OA\Property(property="code", type="number",description="状态码",default="5001"),
         *              @OA\Property(property="msg", type="string",description="提示信息",default="请检查填写的授权码是否正确"),
         *          )
         *     )
         *
         * )
         */
    public function getInfoByAuthCode(Request $request){
        $authCode = $request->input('authCode');
        $key = $request->input('key');
        $res = $this->keyModel->getRecord( $key,$authCode);

        if(!$res){
            return $this->error(5001,'请检查填写的码是否正确');
        }

        return $this->success($res,"已获取".$key."的值");
    }

}
